package com.ndp.fb.exception;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Created by infi.he on 2016/1/21.
 */
public class ResourceMsgManager extends AbstractResourceManager {

    /**
     * 汉语资源包
     */
    public static ResourceBundle cnBundle = ResourceBundle.getBundle("msg", Locale.SIMPLIFIED_CHINESE);

    /**
     * 英文资源包
     */
    public static ResourceBundle usBundle = ResourceBundle.getBundle("msg", Locale.US);


    /**
     * getResource
     *
     * @param key
     * @return
     */
    public static String getResource(String language, String key) {
        ResourceBundle resourceBundle = getResourceBundle(language);
        return getResource(resourceBundle, key);
    }

    /**
     * getResource
     *
     * @param key
     * @return
     */
    public static String getResource(String language, String key, Object... params) {
        ResourceBundle resourceBundle = getResourceBundle(language);
        return getResource(resourceBundle, key, params);
    }

    /**
     * 获取资源文件
     *
     * @param language
     * @return
     */
    private static ResourceBundle getResourceBundle(String language) {
        return isCN(language) ? cnBundle : usBundle;
    }


    public static void main(String[] args) {
        System.out.println(ResourceMsgManager.getResource("zh_CN", "20001", "文本"));
        System.out.println(ResourceMsgManager.getResource("en_US", "20001", "xxx"));
    }
}
